<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<title>Title</title>
	</head>
	<body>
		<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
		<script>
			{
				const list = new Map()
				for (let i = 0; i < 10000; i++) {
					list.set(i, i)
				}
				// doOrderBatch([...list.values()])
			}

			/*
			 * 顺序批量
			 * data 数据源
			 * count 1次几条数据
			 */
			function doOrderBatch(data, count = 100) {
				if (data && data.length) {
					let remain = data.length
					if (!remain) return
					remain = remain - count
					const newData = data.splice(0, count)
					console.log(newData, 'newData')
					doOrderBatch(data, count)
					doOrderBatchAfter(newData)
				}
			}

			function doOrderBatchAfter(data) {
				return doApi(data)
			}

			// API请求
			function doApi(data) {
				if (data && data.length) {
					let url = 'http://127.0.0.1:8081'
					axios.post(url, data).then(() => {})
				}
			}

			{
				const list = new Map()
				for (let i = 0; i < 10000; i++) {
					list.set(i, i)
				}
				doOrderBatch([...list.values()])

				/*
				 * 顺序批量
				 * data 数据源
				 * count 1次几条数据
				 */
				async function doOrderBatch(data, count = 100) {
					if (data && data.length) {
						let url = 'http://127.0.0.1:8081'
						for (let i = 0; i < data.length; i += count) {
							try {
								const newData = data.slice(i, i + count)
								console.log(newData, 'newData')
								await axios.post(url, newData)
							} catch (e) {}
						}
					}
				}

				// function doOrderBatch(data, count = 100, cb) {
				// 	doOrder(0)
				// 	function doOrder(i) {
				// 		try {
				// 			if (i >= data.length) return cb && cb()
				// 			const newData = data.slice(i, i + count)
				// 			console.log(newData, 'newData')
				// 			doOrder(i + count)
				// 			doOrderBatchAfter(newData)
				// 		} catch (e) {}
				// 	}
				// }

				// function doOrderBatchAfter(data) {
				// 	if (data && data.length) {
				// 		let url = 'http://127.0.0.1:8081'
				// 		axios.post(url, data).then(() => {})
				// 	}
				// }
			}
		</script>
	</body>
</html>
